package edu.hawaii.solardecathlon.page.security;

import java.util.Map;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.image.Image;
import org.apache.wicket.markup.html.link.Link;
import edu.hawaii.solardecathlon.page.BasePage;
import edu.hawaii.solardecathlon.page.images.DesignSet;

/**
 * The application security page.
 * 
 * @author Harry Kwan
 */
public class SecurityPage extends BasePage {

  /** Support serialization. */
  private static final long serialVersionUID = 1L;

  /**
   * The security page for this application.
   */
  public SecurityPage() {
    // PMD fix, string literals
    final String security_str = "security";
    final String cur_room_str = "cur_room";
    
    DesignSet room = new DesignSet();
    Map<String, String> props = getSessionProperties(security_str);

    // this is set for prototyping
    props.put("cur_mode", "Manual");

    add(new Label("top_header", "Select the room you wish to configure."));

    /* image links start */
    add(new Link<String>("room01Link") {
      /** Support serialization. */
      private static final long serialVersionUID = 1L;
      Map<String, String> props = getSessionProperties(security_str);

      /** Upon clicking, choose the room. */
      public void onClick() {
        props.put(cur_room_str, "Room");
        setResponsePage(SecurityPage.class);
      }
    }
    .add(new Image("room", room.design_02)));
    add(new Link<String>("room02Link") {
      /** Support serialization. */
      private static final long serialVersionUID = 1L;
      Map<String, String> props = getSessionProperties(security_str);

      /** Upon clicking, choose the room. */
      public void onClick() {
        props.put(cur_room_str, "Natural Space");
        setResponsePage(SecurityPage.class);
      }
    }
    .add(new Image("natural_space", room.design_03)));
    add(new Link<String>("room03Link") {
      /** Support serialization. */
      private static final long serialVersionUID = 1L;
      Map<String, String> props = getSessionProperties(security_str);

      /** Upon clicking, choose the room. */
      public void onClick() {
        props.put(cur_room_str, "Bathroom");
        setResponsePage(SecurityPage.class);
      }
    }
    .add(new Image("bathroom", room.design_04)));
    add(new Link<String>("room04Link") {
      /** Support serialization. */
      private static final long serialVersionUID = 1L;
      Map<String, String> props = getSessionProperties(security_str);

      /** Upon clicking, choose the room. */
      public void onClick() {
        props.put(cur_room_str, "Kitchen");
        setResponsePage(SecurityPage.class);
      }
    }
    .add(new Image("kitchen", room.design_05)));
    add(new Link<String>("room05Link") {
      /** Support serialization. */
      private static final long serialVersionUID = 1L;
      Map<String, String> props = getSessionProperties(security_str);

      /** Upon clicking, choose the room. */
      public void onClick() {
        props.put(cur_room_str, "Living/Dining/Sleeping");
        setResponsePage(SecurityPage.class);
      }
    }
    .add(new Image("living", room.design_06)));
    add(new Link<String>("room06Link") {
      /** Support serialization. */
      private static final long serialVersionUID = 1L;
      Map<String, String> props = getSessionProperties(security_str);

      /** Upon clicking, choose the room. */
      public void onClick() {
        props.put(cur_room_str, "Entrance");
        setResponsePage(SecurityPage.class);
      }
    }
    .add(new Image("entrance", room.design_07)));
    /* image links end */

    // first column
    add(new Label("cur_mode", props.get("cur_mode")));
    add(new Button("mode_load") {
      /** Support serialization. */
      private static final long serialVersionUID = 1L;

      /** Upon clicking, load preset. */
      @Override
      public void onSubmit() {
        // TODO
      }
    });
    add(new Button("mode_del") {
      /** Support serialization. */
      private static final long serialVersionUID = 1L;

      /** Upon clicking, delete preset. */
      @Override
      public void onSubmit() {
        // TODO
      }
    });
    
    add(new Button("mode_save") {
      /** Support serialization. */
      private static final long serialVersionUID = 1L;

      /** Upon clicking, save preset. */
      @Override
      public void onSubmit() {
        // TODO
      }
    });

    // 2nd column
    add(new Button("security_on") {
      /** Support serialization. */
      private static final long serialVersionUID = 1L;

      /** Upon clicking, turn security on. */
      @Override
      public void onSubmit() {
        // TODO
      }
    });
    add(new Label(cur_room_str, props.get(cur_room_str)));
    add(new Button("room_choice") {
      /** Support serialization. */
      private static final long serialVersionUID = 1L;

      /** Upon clicking, choose room from menu below */
      @Override
      public void onSubmit() {
        // TODO
      }
    });

    // 3rd column
    add(new Button("security_off") {
      /** Support serialization. */
      private static final long serialVersionUID = 1L;

      /** Upon clicking, turn security off. */
      @Override
      public void onSubmit() {
        // do nothing for now
        setResponsePage(SecurityPage.class);
      }
    });

    add(new Button("submit") {
      /** Support serialization. */
      private static final long serialVersionUID = 1L;

      /** Upon clicking, save alarm and panic settings. */
      @Override
      public void onSubmit() {
        // TODO
      }
    });
  }
}
